package com.tbb.app.base.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.tbb.app.base.dto.RemarkDTO;
import com.tbb.app.base.entity.Note;
import com.tbb.app.base.search.NotePageSearch;
import com.tbb.app.base.search.RemarkPageSearch;
import com.tbb.app.base.service.IChannelService;
import com.tbb.app.base.service.IFollowService;
import com.tbb.app.base.service.INoteService;
import com.tbb.app.base.service.IUserNoteService;
import com.tbb.app.base.vo.ChannelVO;
import com.tbb.app.base.vo.NoteVO;
import com.tbb.app.base.vo.RemarkVO;
import com.tbb.app.common.entity.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/lj")
@Slf4j
@ApiSupport(order = 2)
@Api(tags = "李佳相关接口")
//@CrossOrigin(origins = "*")
public class LJController {

    @Autowired
    private IChannelService iChannelService;
    @Autowired
    private INoteService iNoteService;
    @Autowired
    private IUserNoteService iUserNoteService;
    @Autowired
    private IFollowService iFollowService;

    @GetMapping("/channel/list")
    @ApiOperation("列表查询频道")
    @ApiOperationSupport(order = 1)
    public BaseResponse<List<ChannelVO>> listChannel() {
        return BaseResponse.data(iChannelService.listVO());
    }

    @PostMapping("/note/page")
    @ApiOperation(value = "根据频道分页查询笔记")
    @ApiOperationSupport(order = 2)
    public BaseResponse<IPage<NoteVO>> pageNote(
            @RequestBody
            @Validated
                    NotePageSearch search) {
        return BaseResponse.data(iNoteService.page(search, false));
    }

    @PostMapping("/noteVideo/page")
    @ApiOperation(value = "查询视频频道数据")
    @ApiOperationSupport(order = 9)
    public BaseResponse<IPage<Note>> pageVideoNote(
            @RequestBody
            @Validated
                    NotePageSearch search) {
        return BaseResponse.data(iNoteService.pageVideo(search, false));
    }

    @GetMapping("/note/like")
    @ApiOperation(value = "点赞笔记")
    @ApiOperationSupport(order = 3)
    public BaseResponse<Object> likeNote(
            @RequestParam
            @ApiParam(value = "笔记id", required = true)
                    String noteId,
            @RequestParam
            @ApiParam(value = "操作类型，必填，0-取消点赞，1-点赞", required = true)
                    int type) {
        iUserNoteService.like(noteId, type);
        return BaseResponse.ok();
    }

    @GetMapping("/note/detail")
    @ApiOperation("查询笔记详情")
    @ApiOperationSupport(order = 4)
    public BaseResponse<NoteVO> detailNote(
            @RequestParam
            @ApiParam(value = "笔记id", required = true)
                    String noteId) {
        return BaseResponse.data(iNoteService.detail(noteId, false));
    }

    @PostMapping("/note/remark/page")
    @ApiOperation("分页查询评论")
    @ApiOperationSupport(order = 5)
    public BaseResponse<IPage<RemarkVO>> pageRemark(
            @RequestBody
            @Validated
                    RemarkPageSearch search) {
        return BaseResponse.data(iUserNoteService.pageRemark(search));
    }

    @GetMapping("/user/follow")
    @ApiOperation(value = "关注用户")
    @ApiOperationSupport(order = 6)
    public BaseResponse<Object> followUser(
            @RequestParam
            @ApiParam(value = "被关注用户id，必填", required = true)
                    String followedId,
            @RequestParam
            @ApiParam(value = "操作类型，必填，0-取消关注，1-关注", required = true)
                    int type) {
        iFollowService.follow(followedId, type);
        return BaseResponse.ok();
    }

    @PostMapping("/note/remark/add")
    @ApiOperation("新增评论")
    @ApiOperationSupport(order = 7)
    public BaseResponse<Object> addRemark(
            @RequestBody
            @Validated
                    RemarkDTO dto) {
        iUserNoteService.addRemark(dto);
        return BaseResponse.ok();
    }

    @GetMapping("/note/collect")
    @ApiOperation("收藏笔记")
    @ApiOperationSupport(order = 8)
    public BaseResponse<Object> collectNote(
            @RequestParam
            @ApiParam(value = "笔记id", required = true)
                    String noteId,
            @RequestParam
            @ApiParam(value = "操作类型，必填，0-取消收藏，1-收藏", required = true)
                    int type) {
        iUserNoteService.collect(noteId, type);
        return BaseResponse.ok();
    }
}
